import { clearToken } from '@/utils/authInterceptor';
 import { post } from '@/utils/request';

/**
 * 用户登录
 * @param data 登录参数
 * @returns 登录结果
 */
export const login = (data: {
  username?: string;
  password?: string;
  mobile?: string;
  captcha?: string;
}) => post('/auth/login', data) as Promise<{
  token: string;
  username: string;
  role: string;
}>;

/**
 * 手机号登录
 * @param data 手机号和验证码
 * @returns 登录结果
 */
export const loginByPhone = (data: {
  phone: string;
  smsCode: string;
}) => post('/auth/loginByPhone', data) as Promise<{
  token: string;
  username: string;
  role: string;
}>;

/**
 * 用户退出登录
 * @returns 退出登录结果
 */
export const logout = () => post('/auth/logout') as Promise<{
  code: number;
  message: string;
  data: null;
}>;

/**
 * 用户注册
 * @param data 注册参数
 * @returns 注册结果
 */
export const register = (data: {
  name: string;
  nickName: string;
  className: string;
  stuNo: string;
  phone: string;
  email: string;
  role: string;
  gender: number;
  password: string;
  avatar: string;
}) => post('/auth/register', data) as Promise<{
  code: number;
  message: string;
  data: null;
}>;
